﻿<Window x:Class="EffectMapStudio.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:p="clr-namespace:Phoenix.Xna.Framework.Presentation;assembly=Phoenix.Xna.Framework.Presentation"
        xmlns:c="clr-namespace:Phoenix.Xna.Framework.Presentation.Converters;assembly=Phoenix.Xna.Framework.Presentation"
        Title="Window1" Height="600" Width="1300"
        x:Name="_effectMapStudio">

    <Window.Resources>
        <c:EffectParameterEditVisibilityConverter x:Key="_epevc"></c:EffectParameterEditVisibilityConverter>
        <c:EffectParameterValueReadonlyConverter x:Key="_epvrc"></c:EffectParameterValueReadonlyConverter>

        <CollectionViewSource x:Key="_effectsSource" Source="{Binding ElementName=_effectMapStudio, Path=Effects}"></CollectionViewSource>
        <CollectionViewSource x:Key="_techniquesSource" Source="{Binding Source={StaticResource _effectsSource}, Path=Techniques, Mode=TwoWay}"></CollectionViewSource>
        <CollectionViewSource x:Key="_parametersSource" Source="{Binding Source={StaticResource _techniquesSource}, Path=Parameters, Mode=TwoWay}"></CollectionViewSource>
        <CollectionViewSource x:Key="_subEffectsSource" Source="{Binding Source={StaticResource _effectsSource}, Path=SubEffects, Mode=TwoWay}"></CollectionViewSource>
    </Window.Resources>

    <Grid>
        <Menu Height="22" Name="menu1" VerticalAlignment="Top">
            <MenuItem Header="File">
                <MenuItem Header="Open" Name="_open" Click="OnOpenClick" />
            </MenuItem>
            <MenuItem Header="Settings" Name="_settings" Click="OnSettingsClick"></MenuItem>
            <MenuItem Header="Save" Name="_save" Click="OnSaveClick"></MenuItem>
        </Menu>
        <Grid Margin="0,28,0,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="150"></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <ListBox Grid.Column="0" x:Name="_effectList" ItemsSource="{Binding Source={StaticResource _effectsSource}}" IsSynchronizedWithCurrentItem="True">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Label Content="{Binding ID}"></Label>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
            <GridSplitter Grid.Column="0" VerticalAlignment="Stretch" Width="5"></GridSplitter>
            <Grid Grid.Column="1">
                <Grid.RowDefinitions>
                    <RowDefinition Height="30"></RowDefinition>
                    <RowDefinition Height="30"></RowDefinition>
                    <RowDefinition Height="30"></RowDefinition>
                    <RowDefinition Height="*"></RowDefinition>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="88"></ColumnDefinition>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Row="0" Grid.Column="0" Margin="0,0,13,0" VerticalAlignment="Center">Name:</TextBlock>
                <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Source={StaticResource _effectsSource}, Path=ID}" Margin="0"></TextBlock>
                <TextBlock Grid.Row="1" Grid.Column="0" Margin="0,0,13,0" VerticalAlignment="Center">Asset:</TextBlock>
                <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Source={StaticResource _effectsSource}, Path=Asset}" Margin="0" Width="Auto"/>
                <TextBlock Grid.Row="2" Grid.Column="0" Margin="0,0,13,0" VerticalAlignment="Center">Technique:</TextBlock>
                <StackPanel Orientation="Horizontal" Grid.Row="2" Grid.Column="1">
                    <ComboBox ItemsSource="{Binding Source={StaticResource _techniquesSource}}" IsSynchronizedWithCurrentItem="True" DisplayMemberPath="Name" SelectedIndex="0" Width="100" HorizontalAlignment="Left"/>
                    <ComboBox ItemsSource="{Binding Source={StaticResource _techniquesSource}}" IsSynchronizedWithCurrentItem="False" DisplayMemberPath="Name" SelectedItem="{Binding Source={StaticResource _effectsSource}, Path=CurrentTechnique}"></ComboBox>
                </StackPanel>
                <Grid Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"></ColumnDefinition>
                        <ColumnDefinition Width="150"></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <ListView Grid.Column="0" ItemsSource="{Binding Source={StaticResource _parametersSource}}" IsSynchronizedWithCurrentItem="True">
                        <ListView.View>
                            <GridView>
                                <GridViewColumn>
                                    <GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <CheckBox IsChecked="{Binding Path=Serialize}"></CheckBox>
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>
                                <GridViewColumn DisplayMemberBinding="{Binding Path=Name}">
                                    <GridViewColumnHeader Content="Name" MinWidth="100"></GridViewColumnHeader>
                                </GridViewColumn>
                                <GridViewColumn DisplayMemberBinding="{Binding Path=ValueType}">
                                    <GridViewColumnHeader Content="Type" MinWidth="100"></GridViewColumnHeader>
                                </GridViewColumn>
                                <GridViewColumn>
                                    <GridViewColumnHeader Content="Value" MinWidth="100"></GridViewColumnHeader>
                                    <GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBox MinWidth="100" HorizontalAlignment="Stretch" Text="{Binding Path=Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="{Binding Path=Type, Converter={StaticResource _epvrc}}"></TextBox>
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>
                                <GridViewColumn>
                                    <GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <Button Click="OnEditClick" Tag="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}}" Visibility="{Binding Path=ValueType, Converter={StaticResource _epevc}}">Edit</Button>
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>
                            </GridView>
                        </ListView.View>
                    </ListView>
                    <GridSplitter Grid.Column="0" VerticalAlignment="Stretch" Width="5"></GridSplitter>
                    <ListBox Grid.Column="1" ItemsSource="{Binding Source={StaticResource _subEffectsSource}}" IsSynchronizedWithCurrentItem="True" ContextMenuOpening="ListBox_ContextMenuOpening">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Label Content="{Binding ID}"></Label>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                        <ListBox.ContextMenu>
                            <ContextMenu x:Name="_subEffectsContextMenu"></ContextMenu>
                        </ListBox.ContextMenu>
                    </ListBox>
                </Grid>
            </Grid>
        </Grid>
    </Grid>

</Window>
